home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-irix.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  2.7 KB  |  105 lines

  1. /* ieee-utils/fp-irix.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Tim Mooney
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <math.h>
  21. #include <ieeefp.h>
  22. #include <gsl/gsl_ieee_utils.h>
  23. #include <gsl/gsl_errno.h>
  24.  
  25. int
  26. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  27. {
  28.   fp_except mode = 0 ;
  29.   fp_rnd    rnd  = 0 ;
  30.  
  31.   switch (precision)
  32.     {
  33.     case GSL_IEEE_SINGLE_PRECISION:
  34.       GSL_ERROR ("IRIX only supports default precision rounding",
  35.          GSL_EUNSUP) ;
  36.       break ;
  37.     case GSL_IEEE_DOUBLE_PRECISION:
  38.       GSL_ERROR ("IRIX only supports default precision rounding",
  39.          GSL_EUNSUP) ;
  40.       break ;
  41.     case GSL_IEEE_EXTENDED_PRECISION:
  42.       GSL_ERROR ("IRIX only supports default precision rounding",
  43.          GSL_EUNSUP) ;
  44.       break ;
  45.     }
  46.  
  47.   switch (rounding)
  48.     {
  49.     case GSL_IEEE_ROUND_TO_NEAREST:
  50.       rnd = FP_RN ;
  51.       fpsetround (rnd) ;
  52.       break ;
  53.     case GSL_IEEE_ROUND_DOWN:
  54.       rnd = FP_RM ;
  55.       fpsetround (rnd) ;
  56.       break ;
  57.     case GSL_IEEE_ROUND_UP:
  58.       rnd = FP_RP ;
  59.       fpsetround (rnd) ;
  60.       break ;
  61.     case GSL_IEEE_ROUND_TO_ZERO:
  62.       rnd = FP_RZ ;
  63.       fpsetround (rnd) ;
  64.       break ;
  65.     default:
  66.       rnd = FP_RN ;
  67.       fpsetround (rnd) ;
  68.     }
  69.  
  70.   /* Turn on all the exceptions apart from 'inexact' */
  71.  
  72.   mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
  73.  
  74.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  75.     mode &= ~ FP_X_INV ;
  76.  
  77.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  78.     GSL_ERROR ("IRIX does not support the denormalized operand exception. "
  79.            "Use 'mask-denormalized' to work around this.",
  80.            GSL_EUNSUP) ;
  81.  
  82.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  83.     mode &= ~ FP_X_DZ ;
  84.  
  85.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  86.     mode &= ~ FP_X_OFL ;
  87.  
  88.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  89.     mode &=  ~ FP_X_UFL ;
  90.  
  91.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  92.     {
  93.       mode |= FP_X_IMP ;
  94.     }
  95.   else
  96.     {
  97.       mode &= ~ FP_X_IMP ;
  98.     }
  99.  
  100.   fpsetmask (mode) ;
  101.  
  102.   return GSL_SUCCESS ;
  103.  
  104. }
  105.